<?php
namespace Gotcha\Core\Components\XML{
    use Gotcha\Core\Components\Debugging\Debugger;
    use Gotcha\Core\Components\XML\Interfaces\IXMLReader;

    class XMLReader implements IXMLReader {
        private $xmlObject;

        public function createXMLObject($data, $options, $dataIsUrl = null, $namespace = null, $isPrefix = null)
        {
            try {
                $this->xmlObject = new \SimpleXMLElement($data, $options, $dataIsUrl, $namespace, $isPrefix);
            } catch (\Exception $ex) {
                Debugger::XMLError(true, true);
            }
        }

        public function getXMLContent()
        {
            return $this->xmlObject;
        }

        public function getNodeKeyValue(\SimpleXMLElement $node, \ArrayObject &$container) {
            try {
                $container->offsetSet((string)$node->attributes()->key, (string)$node->attributes()->value);
            } catch(\Exception $ex) {
                Debugger::Error('Error', $ex, true, true);
            }

            return $container;
        }
    }
}

